﻿using System;
using System.Collections.Generic;

namespace Socium.Domain.Collections {
	public class HashedCache<TKey, TValue> {
		readonly IDictionary<TKey, TValue> _dictionary = new Dictionary<TKey, TValue>();

		public TValue GetItem(TKey key, Func<TKey, TValue> creator) {
			TValue value;
			if (_dictionary.TryGetValue(key, out value)) {
				return value;
			}

			value = creator(key);
			_dictionary.Add(key, value);

			return value;
		}
	}
}
